﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Data;
using Wpf.CommonTools.SystemExtension;

namespace Wpf.CommonTools.Converter
{
    public class MultiStringFormatConverter : IMultiValueConverter
    {
        #region IMultiValueConverter 成员

        object IMultiValueConverter.Convert(object[] values, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            if (DesignerProperties.GetIsInDesignMode(new DependencyObject()))
            {
                return "Design Mode";
            }
            else
            {
                string a = UILanguage.TryFindResource(parameter.ToString());
                string b = string.Format(new CustomerFormatter(), a, values);
                return b;
            }
        }

        object[] IMultiValueConverter.ConvertBack(object value, Type[] targetTypes, object parameter, System.Globalization.CultureInfo culture)
        {
            throw new NotImplementedException();
        }

        #endregion
    }

    public class CustomerFormatter : IFormatProvider, ICustomFormatter
    {
        public object GetFormat(Type formatType)
        {
            if (formatType == typeof(ICustomFormatter))
                return this;
            else
                return null;
        }

        public string Format(string format,
                              object arg,
                              IFormatProvider formatProvider)
        {
            if (!this.Equals(formatProvider))
            {
                return null;
            }
            else
            {
                if (arg == null)
                {
                    return string.Empty;
                }
                else
                {
                    return UILanguage.TryFindResource(arg.ToString());
                }
            }
        }
    }
}
